import { RouteRecordRaw } from "vue-router";
import { defineStore } from "pinia";
import { constantRoutes } from "@/router";
import { store } from "@/store";

interface AsyncRouteState {
  menus: RouteRecordRaw[];
  routers: Array<RouteRecordRaw>;
  addRouters: Array<RouteRecordRaw>;
}

export const useAsyncRouteStore = defineStore({
  id: "app-async-route",
  state: (): AsyncRouteState => ({
    menus: [],
    routers: constantRoutes, // 默认值为静态路由.
    addRouters: [],
  }),
  actions: {
    setRouters(routers: Array<RouteRecordRaw>) {
      this.routers = constantRoutes.concat(routers);
    },
    async generateRoutes() {
      // let accessedRouters;
      try {
        // accessedRouters = await generatorDynamicRouter();
        // console.log(accessedRouters);
        return [] as RouteRecordRaw[];
      } catch (e) {
        console.log(e);
      }
    },
  },
});

export const useAsyncRouteStoreOutSetup = () => {
  return useAsyncRouteStore(store);
};
